<?php
/**
 * Created by PhpStorm.
 * User: yyq
 * Date: 2018/10/22
 * Time: 22:34
 */

namespace Common\Model;


class RefundModel extends CommonModel
{
    const STATUS_WAIT   = 'wait';//
    const STATUS_ACCEPT = 'accept';//
    const STATUS_REFUSE = 'refuse';//

    /**
     * @param $status
     * @return string
     */
    public function statusToString($status) {
        switch ($status) {
            case self::STATUS_WAIT:
                return '待审核';
                break;
            case self::STATUS_ACCEPT:
                return '已退款';
                break;
            case self::STATUS_REFUSE:
                return '已拒绝';
                break;
            default:
                return '未知';
                break;
        }
    }

    /**
     * @return string
     * 生成退款订单编号
     */
    public function getRefundOrder() {
        $num = 'R'.date('Ymd') . str_pad(mt_rand(1, 99999), 5, '0', STR_PAD_LEFT);
        if($this->where(['out_refund_no' => $num])->find()) {
            self::getRefundOrder();
        }
        return $num;
    }
}